package com.locatead.proto.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.locatead.proto.dao.CellDAO;
import com.locatead.proto.model.Cell;
import com.locatead.proto.util.auth.exception.UnauthorizedException;

/*
 * Cell Service
 * 
 */
@Component
public class CellService {
	@Autowired
	private CellDAO dao;
	
	
	public String wrap(String msg) {
		return "(" + msg + ", " + dao.getConnectionInfo() + ")";
	}
	
	public String dbTest() {
		return dao.dbTest();
	}
	
	public Cell getCell(Integer x, Integer y) {
		return dao.getCell(x, y);
	}
	
	/*
	 * Testing Only
	 */
	public void initCellDB(String id, String passwd) throws UnauthorizedException {
		try {
			dao.initCellDB(id, passwd);
		} catch (UnauthorizedException e) {
			throw new UnauthorizedException("Invalid developer: " + id);
		}
	}
}
